<?php
/**
 * Created by PhpStorm.
 * User: wei
 * Date: 2016/6/21
 * Time: 11:49
 */
namespace Admin\Controller;
use Think\Controller;

class InvoiceController extends CommonController
{
    protected function _initialize()
    {
        parent::_initialize();
        $this->breadcrumb1 = '财务管理';
        $this->breadcrumb2 = '发票税费邮费管理';
        $this->url = U('Invite/index');
    }

    //index
    public function index(){
        $date1=I('post.time1');
        $date2=I('post.time2');
        $number=I('post.number');
        $where['is_pay']=1;

        if($date1 && $date2){
            $time1=strtotime($date1);
            $time2=strtotime($date2);
            $where['add_time']=array('between',array($time1,$time2));
        }

        if($number){
            $where['number']=$number;
        }
        $total=M('invoice')->where($where)->field('sum(money) money,sum(tax) tax,sum(postage) postage')->select();
        if(!empty($where)){
            $count=M('invoice')->where($where)->count();
            $Page       = new \Think\Page($count,25);
            $list=M('invoice')->where($where)
                ->order('add_time desc')
                ->limit($Page->firstRow,$Page->listRows)
                ->field('*,(money+tax+postage) total')
                ->select();

        }else{
            $count=M('invoice')->count();
            $Page       = new \Think\Page($count,25);
            $list=M('invoice')->where($where)
                ->order('add_time desc')
                ->limit($Page->firstRow,$Page->listRows)->field('*,(money+tax+postage) total')->select();
        }
        $show  = $Page->show();// 分页显示输出
        $this->assign('list',$list);
        $this->assign('page',$show);
        $this->assign('total',$total);
        $this->display();
    }


    //详情
    public function detail(){
        $id=I('get.id');
        $where['number']=$id;
        $list=M('invoice')->where()->find();
        $this->assign('list',$list);
        $this->display();
    }
}